// 导入需要的config和request
import confing from '../../config/config.js';
import request from '../../util/request.js';


// 申明请求对象
const workshopRequest = {
    // itemtype请求的基本url
    BASE_URL: confing.SYS_URL + "/workshop",

    list(page = 1, limit = 10, workshop, callbcak) {
        // url
        let url = this.BASE_URL + "/list?page=" + page + "&limit=" + limit;
        if (workshop) {
            if (workshop.workshopCode) {
                url += "&workshopCode=" + workshop.workshopCode;
            }
            if (workshop.workshopName) {
                url += "&workshopName=" + workshop.workshopName;
            }

        }
        // 发送请求
        request.get(url, callbcak);
    },

    /**
* 保存车间
* @param {*} workshop  车间对象
* @param {*} callback  回调函数
*/
    saveWorkshop(workshop, callback) {
        let url = this.BASE_URL + "/save";
        request.post(url, workshop, callback);
    },

    /**
 * 根据id加载车间信息
 * @param {*} workshopId 车间编号
 * @param {*} callback 回调函数
 */
    get(workshopId, callback) {
        if (workshopId) {
            // 准备url
            let url = this.BASE_URL + "/get?workshopId=" + workshopId;
            request.get(url, callback);
        }
        // 如果没有workshopId，不做任何处理
    },
    /**
 * 根据ID编辑车间信息
 * @param {} workshop 
 * @param {*} callback  
 */
    edit(workshop, callback) {
        if (workshop != undefined && workshop.workshopId != undefined) {
            request.put(this.BASE_URL + "/update", workshop, callback);
        }
    },

            /**
     * 根据ID删除车间
     * @param {*} workshopId 
     * @param {*} callback 
     */
            delete(workshopId,callback){
                request.delete(this.BASE_URL + "/" + workshopId,callback);
            },
            /**
     * 根据ID批量删除车间,url的遍历,和后端没关系
     * @param {*} workshopIds
     * @param {*} callback 
     */
    deleteSelect(workshopIds, callback) {
        // 拼接URL
        let url = this.BASE_URL + "/deletes?t=1";
        if (workshopIds != undefined) {
            workshopIds.forEach(workshopId => {
                url += "&workshopId=" + workshopId;
            });//看这个字段&workshopId=:
            request.delete(url, callback);
        }
    },




}
// 将itemtypeRequest暴漏出去
export default workshopRequest;